//package cn.itsource.service.impl;
//import cn.itsource.domain.Goods;
//import cn.itsource.mapper.GoodsMapper;
//import cn.itsource.service.IGoodsService;
//import cn.itsource.utils.DbGoodsLock;
//import cn.itsource.utils.RedissionUtils;
//import org.redisson.api.RLock;
//import org.redisson.api.RedissonClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import java.util.Map;
//import java.util.concurrent.locks.Lock;
//import java.util.concurrent.locks.ReentrantLock;
//
//@Service
//public class GoodsServiceImplLock implements IGoodsService {
//
//    @Autowired
//    private GoodsMapper goodsMapper;
//    Lock lock = new ReentrantLock();
//    @Override
//    public Goods getById(Long id) {
//        return goodsMapper.laodById(1L);
//    }
//
//
//    @Override
//    @Transactional
//    public void updateNum(Map<String,Object> params) {
//        Long goodsId = (Long) params.get("id");
//        Integer num = (Integer) params.get("num");
//        try{
//            lock.lock();
//            System.out.println(Thread.currentThread().getName()+" get lock！");
//            Goods goods = goodsMapper.laodById(goodsId);
//            Thread.sleep(10000);
//            System.out.println(goods);
//            System.out.println(Thread.currentThread().getName()+goods.getCount()+":"+num);
//            if (goods.getCount()>=num){
//                goodsMapper.updateNum(params);
//                System.out.println(Thread.currentThread().getName()+"buy "+num+"！");
//
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }finally {
//            if (lock != null) {
//                lock.unlock();
//            }
//        }
//
//
//    }
//}
